import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:travel/routes/index.dart';
import 'package:travel/screen/flutter_screenutil.dart';
import 'package:travel/utils/colors.dart';
import 'package:travel/utils/radian.dart';
import 'package:travel/utils/styles.dart';
import 'package:travel/utils/tools.dart';

class MineController extends GetxController {
  RxInt coupon = 3.obs;
}

class MinePage extends GetView<MineController> {
  const MinePage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        builder: (_) {
          return Obx(() => Scaffold(
              backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF7f7),
              body: statusBar(context)));
        },
        init: Get.put(MineController()));
  }

  Widget statusBar(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.light,
        child: CustomScrollView(
          slivers: [
            SliverPersistentHeader(
              pinned: true,
              delegate: _SliverCustomHeader(),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: 10.h),
                alignment: Alignment.center,
                child: Container(
                  width: 345.w,
                  height: 85.h,
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: CustomPaint(
                    painter: _MyPainter(),
                    child: Row(
                      children: [
                        Expanded(
                            child: InkWell(
                          onTap: () {
                            Get.toNamed(RoutePath.mineCoupon);
                          },
                          child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child: SizedBox(
                                  width: 26,
                                  height: 22,
                                  child: Stack(
                                    clipBehavior: Clip.none,
                                    children: [
                                      Container(
                                        child: ToolsUtils.assetImageSvg('u2794.svg',
                                            width: 26, height: 22),
                                      ),
                                      Container(
                                        margin: const EdgeInsets.only(left: 4, top: 2),
                                        child: ToolsUtils.assetImageSvg('u2795.svg',
                                            width: 26, height: 22),
                                      )
                                    ],
                                  ),
                                ),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '优惠券：${controller.coupon.value} 张',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color0000, fontSize: 13.sp),
                                ),
                              ))
                            ],
                          ),
                        )),
                        Expanded(
                            child: InkWell(
                          onTap: () {
                            Get.toNamed(RoutePath.mineCoin);
                          },
                          child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                      child: Image.network(
                                'https://img1.baidu.com/it/u=1071326613,2357694969&fm=253&fmt=auto&app=138&f=PNG?w=145&h=150',
                                width: 26,
                                height: 22,
                              ))),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '金币：${NumberFormat('#,###').format(3000)} 个',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color0000, fontSize: 13.sp),
                                ),
                              ))
                            ],
                          ),
                        ))
                      ],
                    ),
                  ),
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: 10.h),
                alignment: Alignment.center,
                child: Container(
                  width: 345.w,
                  height: 130.h,
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: 15.w, top: 15.h, bottom: 10.h),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '我的门票',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                        ),
                      ),
                      Expanded(
                          child: Row(
                        children: [
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u356.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '全部门票',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          )),
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u354.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '待付款',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          )),
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u355.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '未使用',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          )),
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u353.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '待评价',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          ))
                        ],
                      ))
                    ],
                  ),
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: 10.h),
                alignment: Alignment.center,
                child: Container(
                  width: 345.w,
                  height: 180.h,
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: 15.w, top: 15.h, bottom: 15.h),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '基础服务',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                        ),
                      ),
                      Expanded(
                          child: AlignedGridView.count(
                              crossAxisCount: 4,
                              itemBuilder: (context, index) {
                                var list = countBase(context);
                                return list.elementAt(index);
                              },
                              mainAxisSpacing: 20.h,
                              itemCount: countBase(context).length,
                              crossAxisSpacing: 0,
                              semanticChildCount: countBase(context).length,
                              padding: EdgeInsets.zero,
                              physics: const NeverScrollableScrollPhysics()))
                    ],
                  ),
                ),
              ),
            ),
          ],
        ));
  }

  List<Widget> countBase(BuildContext context) {
    return [
      Column(
        children: [
          Container(
            alignment: Alignment.center,
            child: ToolsUtils.assetImageSvg('u384.svg', width: 23.w, height: 24.h),
          ),
          Container(
            margin: EdgeInsets.only(top: 4.h),
            alignment: Alignment.center,
            child: Container(
              alignment: Alignment.center,
              constraints: BoxConstraints.expand(width: 66.w, height: 25.h),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(13),
                  border: Border.all(
                      color: ColorsUtils.parseColorFromHexString(ColorsUtils.color3478))),
              child: Text(
                '我要发布',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color3478, fontSize: 12.sp),
              ),
            ),
          )
        ],
      ),
      Column(
        children: [
          Container(
            alignment: Alignment.center,
            child: ToolsUtils.assetImageSvg('u372.svg', width: 18.w, height: 24.h),
          ),
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(top: 8.h),
            child: Text(
              '酒店订单',
              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
            ),
          )
        ],
      ),
      Stack(
        children: [
          Column(
            children: [
              Container(
                padding: const EdgeInsets.only(top: 5),
                alignment: Alignment.center,
                child: ToolsUtils.assetImageSvg('u375.svg', width: 27.w, height: 18.h),
              ),
              Container(
                alignment: Alignment.bottomCenter,
                margin: EdgeInsets.only(top: 8.h),
                child: Text(
                  '我的机票',
                  style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
                ),
              )
            ],
          ),
          Positioned(
              top: 0,
              left: 15,
              width: 32,
              height: 32,
              child: CustomPaint(
                  painter: _MyCustomPaint(),
                  child: Transform.rotate(
                    angle: RadianUtils.angleToRadian(318),
                    child: Container(
                      padding: const EdgeInsets.only(top: 5),
                      alignment: Alignment.topCenter,
                      child: Text(
                        '规划中',
                        style: StylesUtils.customTextStyle(
                            fontSize: 8.sp,
                            color: ColorsUtils.color3333,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                  ))),
        ],
      ),
      Stack(
        children: [
          Column(
            children: [
              Container(
                padding: const EdgeInsets.only(top: 5),
                alignment: Alignment.center,
                child: ToolsUtils.assetImageSvg('u366.svg', width: 27.w, height: 18.h),
              ),
              Container(
                alignment: Alignment.bottomCenter,
                margin: EdgeInsets.only(top: 8.h),
                child: Text(
                  '我的车票',
                  style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
                ),
              )
            ],
          ),
          Positioned(
              top: 0,
              left: 15,
              width: 32,
              height: 32,
              child: CustomPaint(
                  painter: _MyCustomPaint(),
                  child: Transform.rotate(
                    angle: RadianUtils.angleToRadian(318),
                    child: Container(
                      padding: const EdgeInsets.only(top: 5),
                      alignment: Alignment.topCenter,
                      child: Text(
                        '规划中',
                        style: StylesUtils.customTextStyle(
                            fontSize: 8.sp,
                            color: ColorsUtils.color3333,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                  ))),
        ],
      ),
      Column(
        children: [
          Container(
            alignment: Alignment.center,
            child: ToolsUtils.assetImageSvg('u363.svg', width: 24.w, height: 24.h),
          ),
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(top: 8.h),
            child: Text(
              '我的金币',
              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
            ),
          )
        ],
      ),
      InkWell(
        onTap: () {
          Get.toNamed(RoutePath.mineCollect);
        },
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              child: ToolsUtils.assetImageSvg('u387.svg', width: 24.w, height: 24.h),
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 8.h),
              child: Text(
                '我的收藏',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
              ),
            )
          ],
        ),
      ),
      InkWell(
        onTap: () {
          Get.toNamed(RoutePath.customerChat);
        },
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              child: ToolsUtils.assetImageSvg('u381.svg', width: 24.w, height: 24.h),
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 8.h),
              child: Text(
                '联系客服',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
              ),
            )
          ],
        ),
      ),
      InkWell(
          onTap: () {
            Get.toNamed(RoutePath.opinionFeedback);
          },
          child: Column(
            children: [
              Container(
                alignment: Alignment.center,
                child: ToolsUtils.assetImageSvg('u360.svg', width: 24.w, height: 24.h),
              ),
              Container(
                alignment: Alignment.center,
                margin: EdgeInsets.only(top: 8.h),
                child: Text(
                  '意见反馈',
                  style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
                ),
              )
            ],
          ))
    ];
  }
}

class MineView extends StatefulWidget {
  const MineView({super.key});

  @override
  State<MineView> createState() => _MineViewState();
}

class _MineViewState extends State<MineView> {
  int coupon = 3;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF7f7),
        body: statusBar(context));
  }

  Widget statusBar(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.light,
        child: CustomScrollView(
          slivers: [
            SliverPersistentHeader(
              pinned: true,
              delegate: _SliverCustomHeader(),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: 10.h),
                alignment: Alignment.center,
                child: Container(
                  width: 345.w,
                  height: 85.h,
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: CustomPaint(
                    painter: _MyPainter(),
                    child: Row(
                      children: [
                        Expanded(
                            child: InkWell(
                          onTap: () {
                            Get.toNamed(RoutePath.mineCoupon);
                          },
                          child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child: SizedBox(
                                  width: 26,
                                  height: 22,
                                  child: Stack(
                                    clipBehavior: Clip.none,
                                    children: [
                                      Container(
                                        child: ToolsUtils.assetImageSvg('u2794.svg',
                                            width: 26, height: 22),
                                      ),
                                      Container(
                                        margin: const EdgeInsets.only(left: 4, top: 2),
                                        child: ToolsUtils.assetImageSvg('u2795.svg',
                                            width: 26, height: 22),
                                      )
                                    ],
                                  ),
                                ),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '优惠券：$coupon 张',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color0000, fontSize: 13.sp),
                                ),
                              ))
                            ],
                          ),
                        )),
                        Expanded(
                            child: InkWell(
                          onTap: () {
                            Get.toNamed(RoutePath.mineCoin);
                          },
                          child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                      child: Image.network(
                                'https://img1.baidu.com/it/u=1071326613,2357694969&fm=253&fmt=auto&app=138&f=PNG?w=145&h=150',
                                width: 26,
                                height: 22,
                              ))),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '金币：${NumberFormat('#,###').format(3000)} 个',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color0000, fontSize: 13.sp),
                                ),
                              ))
                            ],
                          ),
                        ))
                      ],
                    ),
                  ),
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: 10.h),
                alignment: Alignment.center,
                child: Container(
                  width: 345.w,
                  height: 130.h,
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: 15.w, top: 15.h, bottom: 10.h),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '我的门票',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                        ),
                      ),
                      Expanded(
                          child: Row(
                        children: [
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u356.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '全部门票',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          )),
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u354.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '待付款',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          )),
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u355.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '未使用',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          )),
                          Expanded(
                              child: Column(
                            children: [
                              Expanded(
                                  child: Center(
                                child:
                                    ToolsUtils.assetImageSvg('u353.svg', width: 25.w, height: 28.h),
                              )),
                              Expanded(
                                  child: Align(
                                alignment: Alignment.topCenter,
                                child: Text(
                                  '待评价',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 13.sp, color: ColorsUtils.color3333),
                                ),
                              ))
                            ],
                          ))
                        ],
                      ))
                    ],
                  ),
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: 10.h),
                alignment: Alignment.center,
                child: Container(
                  width: 345.w,
                  height: 180.h,
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: 15.w, top: 15.h, bottom: 15.h),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '基础服务',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                        ),
                      ),
                      Expanded(
                          child: AlignedGridView.count(
                              crossAxisCount: 4,
                              itemBuilder: (context, index) {
                                var list = countBase(context);
                                return list.elementAt(index);
                              },
                              mainAxisSpacing: 20.h,
                              itemCount: countBase(context).length,
                              crossAxisSpacing: 0,
                              semanticChildCount: countBase(context).length,
                              padding: EdgeInsets.zero,
                              physics: const NeverScrollableScrollPhysics()))
                    ],
                  ),
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: 10.h),
                alignment: Alignment.center,
                child: Container(
                  width: 345.w,
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: 15.w, top: 15.h, bottom: 15.h),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '技术服务',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: TextButton(
                            onPressed: () {
                              Get.toNamed(RoutePath.homeAuth);
                            },
                            child: Text(
                              '指纹支持',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                            )),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: TextButton(
                            onPressed: () {
                              Get.toNamed(RoutePath.homeFaces);
                            },
                            child: Text(
                              '人脸支持',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                            )),
                      )
                    ],
                  ),
                ),
              ),
            ),
            SliverPadding(
              padding: EdgeInsets.symmetric(vertical: 50.h),
              sliver: SliverToBoxAdapter(
                child: Container(
                  height: 50.h,
                ),
              ),
            )
          ],
        ));
  }

  List<Widget> countBase(BuildContext context) {
    return [
      InkWell(
        onTap: () {
          Get.toNamed(RoutePath.attractionsPublish);
        },
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              child: ToolsUtils.assetImageSvg('u384.svg', width: 23.w, height: 24.h),
            ),
            Container(
              margin: EdgeInsets.only(top: 4.h),
              alignment: Alignment.center,
              child: Container(
                alignment: Alignment.center,
                constraints: BoxConstraints.expand(width: 66.w, height: 25.h),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(13),
                    border: Border.all(
                        color: ColorsUtils.parseColorFromHexString(ColorsUtils.color3478))),
                child: Text(
                  '我要发布',
                  style: StylesUtils.customTextStyle(color: ColorsUtils.color3478, fontSize: 12.sp),
                ),
              ),
            )
          ],
        ),
      ),
      InkWell(
        onTap: () {
          Get.toNamed(RoutePath.hotelOrderList);
        },
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              child: ToolsUtils.assetImageSvg('u372.svg', width: 18.w, height: 24.h),
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 8.h),
              child: Text(
                '酒店订单',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
              ),
            )
          ],
        ),
      ),
      Stack(
        children: [
          Column(
            children: [
              Container(
                padding: const EdgeInsets.only(top: 5),
                alignment: Alignment.center,
                child: ToolsUtils.assetImageSvg('u375.svg', width: 27.w, height: 18.h),
              ),
              Container(
                alignment: Alignment.bottomCenter,
                margin: EdgeInsets.only(top: 8.h),
                child: Text(
                  '我的机票',
                  style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
                ),
              )
            ],
          ),
          Positioned(
              top: 0,
              left: 15,
              width: 32,
              height: 32,
              child: CustomPaint(
                  painter: _MyCustomPaint(),
                  child: Transform.rotate(
                    angle: RadianUtils.angleToRadian(318),
                    child: Container(
                      padding: const EdgeInsets.only(top: 5),
                      alignment: Alignment.topCenter,
                      child: Text(
                        '规划中',
                        style: StylesUtils.customTextStyle(
                            fontSize: 8.sp,
                            color: ColorsUtils.color3333,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                  ))),
        ],
      ),
      Stack(
        children: [
          Column(
            children: [
              Container(
                padding: const EdgeInsets.only(top: 5),
                alignment: Alignment.center,
                child: ToolsUtils.assetImageSvg('u366.svg', width: 27.w, height: 18.h),
              ),
              Container(
                alignment: Alignment.bottomCenter,
                margin: EdgeInsets.only(top: 8.h),
                child: Text(
                  '我的车票',
                  style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
                ),
              )
            ],
          ),
          Positioned(
              top: 0,
              left: 15,
              width: 32,
              height: 32,
              child: CustomPaint(
                  painter: _MyCustomPaint(),
                  child: Transform.rotate(
                    angle: RadianUtils.angleToRadian(318),
                    child: Container(
                      padding: const EdgeInsets.only(top: 5),
                      alignment: Alignment.topCenter,
                      child: Text(
                        '规划中',
                        style: StylesUtils.customTextStyle(
                            fontSize: 8.sp,
                            color: ColorsUtils.color3333,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                  ))),
        ],
      ),
      Column(
        children: [
          Container(
            alignment: Alignment.center,
            child: ToolsUtils.assetImageSvg('u363.svg', width: 24.w, height: 24.h),
          ),
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(top: 8.h),
            child: Text(
              '我的金币',
              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
            ),
          )
        ],
      ),
      InkWell(
        onTap: () {
          Get.toNamed(RoutePath.mineCollect);
        },
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              child: ToolsUtils.assetImageSvg('u387.svg', width: 24.w, height: 24.h),
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 8.h),
              child: Text(
                '我的收藏',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
              ),
            )
          ],
        ),
      ),
      InkWell(
        onTap: () {
          Get.toNamed(RoutePath.customerChat);
        },
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              child: ToolsUtils.assetImageSvg('u381.svg', width: 24.w, height: 24.h),
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 8.h),
              child: Text(
                '联系客服',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
              ),
            )
          ],
        ),
      ),
      InkWell(
          onTap: () {
            Get.toNamed(RoutePath.opinionFeedback);
          },
          child: Column(
            children: [
              Container(
                alignment: Alignment.center,
                child: ToolsUtils.assetImageSvg('u360.svg', width: 24.w, height: 24.h),
              ),
              Container(
                alignment: Alignment.center,
                margin: EdgeInsets.only(top: 8.h),
                child: Text(
                  '意见反馈',
                  style: StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 12.sp),
                ),
              )
            ],
          ))
    ];
  }
}

class _SliverCustomHeader extends SliverPersistentHeaderDelegate {
  _SliverCustomHeader();

  void updateStatusBarBrightness(shrinkOffset) {
    if (shrinkOffset > 50) {
      SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
        statusBarBrightness: Brightness.dark,
        statusBarIconBrightness: Brightness.dark,
      ));
    } else {
      SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.light,
      ));
    }
  }

  Color makeStickyHeaderBgColor(shrinkOffset) {
    final int alpha = (shrinkOffset / (maxExtent - minExtent) * 255).clamp(0, 255).toInt();
    return Color.fromARGB(alpha, 255, 255, 255);
  }

  Color makeStickyHeaderTextColor(shrinkOffset, isIcon) {
    if (shrinkOffset <= 30) {
      return isIcon ? Colors.white : Colors.transparent;
    } else {
      final int alpha = (shrinkOffset / (maxExtent - minExtent) * 255).clamp(0, 255).toInt();
      return Color.fromARGB(alpha, 0, 0, 0);
    }
  }

  @override
  Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
    return SizedBox(
      height: maxExtent,
      child: Stack(
        fit: StackFit.expand,
        clipBehavior: Clip.none,
        children: <Widget>[
          Container(
            alignment: Alignment.bottomCenter,
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [ColorsUtils.rgba(52, 120, 246, 1), ColorsUtils.rgba(2, 167, 240, 1)],
                    stops: const [0, 0.99],
                    transform: GradientRotation(RadianUtils.angleToRadian(90)))),
            child: Container(
              margin: EdgeInsets.only(top: 90.h),
              padding: EdgeInsets.symmetric(horizontal: 15.w),
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(15.w), topRight: Radius.circular(15.w))),
              child: Column(
                children: [
                  SizedBox(
                    height: 50,
                    child: Row(
                      children: [
                        Transform.translate(
                          offset: const Offset(0, -15),
                          child: const CircleAvatar(
                            radius: 35,
                            backgroundColor: Colors.white,
                            child: CircleAvatar(
                              radius: 34,
                              backgroundImage: NetworkImage(
                                  'https://img0.baidu.com/it/u=2302354292,2740585901&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1705597200&t=6afd2c05795b34401b494114377e39dc'),
                            ),
                          ),
                        ),
                        Expanded(
                            child: InkWell(
                          onTap: () {
                            Get.toNamed(RoutePath.follow, arguments: {'index': 0});
                          },
                          child: Column(
                            children: [
                              Expanded(
                                  child: Align(
                                alignment: Alignment.bottomCenter,
                                child: Text(
                                  '102',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 15.sp, color: ColorsUtils.color0000),
                                ),
                              )),
                              Expanded(
                                  child: Center(
                                child: Text(
                                  '关注',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 12.sp, color: ColorsUtils.color9999),
                                ),
                              ))
                            ],
                          ),
                        )),
                        Expanded(
                            child: InkWell(
                          onTap: () {
                            Get.toNamed(RoutePath.follow, arguments: {'index': 1});
                          },
                          child: Column(
                            children: [
                              Expanded(
                                  child: Align(
                                alignment: Alignment.bottomCenter,
                                child: Text(
                                  NumberFormat('#,###').format(13687),
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 15.sp, color: ColorsUtils.color0000),
                                ),
                              )),
                              Expanded(
                                  child: Center(
                                child: Text(
                                  '粉丝',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 12.sp, color: ColorsUtils.color9999),
                                ),
                              ))
                            ],
                          ),
                        )),
                        Expanded(
                            child: Column(
                          children: [
                            Expanded(
                                child: Align(
                              alignment: Alignment.bottomCenter,
                              child: Text(
                                '61万',
                                style: StylesUtils.customTextStyle(
                                    fontSize: 15.sp, color: ColorsUtils.color0000),
                              ),
                            )),
                            Expanded(
                                child: Center(
                              child: Text(
                                '点赞',
                                style: StylesUtils.customTextStyle(
                                    fontSize: 12.sp, color: ColorsUtils.color9999),
                              ),
                            ))
                          ],
                        )),
                      ],
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: EdgeInsets.symmetric(vertical: 10.h),
                    child: Text(
                      '晚风心里吹',
                      style: StylesUtils.customTextStyle(
                          color: ColorsUtils.color0000,
                          fontSize: 18.sp,
                          fontWeight: FontWeight.bold),
                    ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Wrap(
                        spacing: 5,
                        children: [
                          Container(
                            constraints: const BoxConstraints.expand(width: 35, height: 18),
                            decoration: BoxDecoration(
                                color: ColorsUtils.rgba(249, 240, 217, 1),
                                borderRadius: BorderRadius.circular(9)),
                            alignment: Alignment.center,
                            child: Text(
                              'Lv.1',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.colorEa8e, fontSize: 12.sp),
                            ),
                          ),
                          Container(
                            constraints: const BoxConstraints.expand(width: 40, height: 18),
                            decoration: BoxDecoration(
                                color: ColorsUtils.rgba(253, 231, 234, 1),
                                borderRadius: BorderRadius.circular(9)),
                            alignment: Alignment.center,
                            child: Text.rich(TextSpan(children: [
                              WidgetSpan(
                                  child:
                                      ToolsUtils.assetImageSvg('u2876.svg', width: 12, height: 12),
                                  alignment: PlaceholderAlignment.middle),
                              TextSpan(
                                  text: ' 男',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.colorEc80, fontSize: 12.sp))
                            ])),
                          )
                        ],
                      ),
                      InkWell(
                        onTap: () {
                          Get.toNamed(RoutePath.homepage);
                        },
                        child: Text.rich(TextSpan(children: [
                          TextSpan(
                              text: '个人主页',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color9999, fontSize: 12.sp)),
                          WidgetSpan(
                              child: Icon(
                                Icons.arrow_forward_ios_rounded,
                                color: ColorsUtils.parseColorFromHexString(ColorsUtils.color9999),
                                size: 12.sp,
                              ),
                              alignment: PlaceholderAlignment.middle)
                        ])),
                      )
                    ],
                  )
                ],
              ),
            ),
          ),
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            child: Container(
              color: makeStickyHeaderBgColor(shrinkOffset),
              child: SafeArea(
                bottom: false,
                child: SizedBox(
                  height: 40,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      IconButton(
                        icon: Icon(
                          Icons.settings_overscan,
                          color: makeStickyHeaderTextColor(shrinkOffset, true),
                        ),
                        onPressed: () {

                        },
                      ),
                      Expanded(
                          child: Center(
                              child: Text(
                        '晚风心里吹',
                        style: TextStyle(
                          fontSize: 18.sp,
                          fontWeight: FontWeight.w500,
                          color: makeStickyHeaderTextColor(shrinkOffset, false),
                        ),
                      ))),
                      IconButton(
                        icon: Icon(
                          Icons.settings,
                          color: makeStickyHeaderTextColor(shrinkOffset, true),
                        ),
                        onPressed: () {
                          Get.toNamed(RoutePath.setting);
                        },
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  double get maxExtent => 230;

  @override
  double get minExtent => 40 + Get.mediaQuery.padding.top;

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
    return this != oldDelegate;
  }
}

class _MyPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)
      ..strokeWidth = 2
      ..style = PaintingStyle.stroke;
    double mid = size.width / 2;
    double y = (size.height - 50) / 2;
    Offset p1 = Offset(mid, y);
    Offset p2 = Offset(mid, y + 50);
    canvas.drawLine(p1, p2, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return this != oldDelegate;
  }
}

class _MyCustomPaint extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = ColorsUtils.parseColorFromHexString('#FECF54')
      ..isAntiAlias = true
      ..style = PaintingStyle.fill;
    Path path = Path();
    path.moveTo(0, 12);
    path.lineTo(0, size.height);
    path.lineTo(size.width, 0);
    path.lineTo(12, 0);
    path.close();
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return this != oldDelegate;
  }
}
